package com.webull.information.center.carwler.common.context;

import java.util.concurrent.ThreadPoolExecutor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 公共的bean
 * 
 * @author smj
 * @Date 2017年7月28日上午10:50:31
 * @version 1.0
 *
 */
@Configuration
public class CarwlerComponent {


	// <task:executor id="executor_news" pool-size="${task.executor:40}"
	// queue-capacity="200" rejection-policy="CALLER_RUNS"/>
	// <task:executor id="executor_splan" pool-size="${task.executor:40}"
	// queue-capacity="200" rejection-policy="CALLER_RUNS"/>
	//
	// <task:executor id="executor_s3" pool-size="${task.executor:1}"
	// queue-capacity="60" rejection-policy="CALLER_RUNS"/>
	@Bean(name = "executor_news", destroyMethod = "destroy")
	public ThreadPoolTaskExecutor genExecutorNews() {
		ThreadPoolTaskExecutor tpool = new ThreadPoolTaskExecutor();
		tpool.setMaxPoolSize(40);
		tpool.setQueueCapacity(200);
		tpool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
		tpool.initialize();
		return tpool;
	}

	@Bean(name = "executor_splan", destroyMethod = "destroy")
	public ThreadPoolTaskExecutor genExecutorSpaln() {
		ThreadPoolTaskExecutor tpool = new ThreadPoolTaskExecutor();
		tpool.setMaxPoolSize(40);
		tpool.setQueueCapacity(200);
		tpool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
		tpool.initialize();
		return tpool;
	}

	@Bean(name = "executor_s3", destroyMethod = "destroy")
	public ThreadPoolTaskExecutor genExecutorS3() {
		ThreadPoolTaskExecutor tpool = new ThreadPoolTaskExecutor();
		tpool.setMaxPoolSize(1);
		tpool.setQueueCapacity(20);
		tpool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
		tpool.initialize();
		return tpool;
	}

}
